

#ifndef _ZK_CFG_H_
#define _ZK_CFG_H_

#include <stdint.h>

/*===================================================================*/
#define ZKCFG_PAGE_MANU		1
#define ZKCFG_PAGE_KEY		2
#define ZKCFG_PAGE_CFG		3

#define ZKCFG_KT_DES		1
#define ZKCFG_KT_AES		2

#define ZKCFG_APP_PRIV		0
#define ZKCFG_APP_CRED		1

#define ZKCFG_KID_PRIV		0
#define ZKCFG_KID_CRED		1


#pragma pack(1)

typedef struct {
	uint32_t time_stamp;
	uint16_t version;
	uint8_t div[8];
}zkcfg_app_t;

typedef struct {
	uint8_t kid;
	uint8_t type;
	uint8_t length;
	uint8_t key[16];
}zkcfg_key_data_t;

typedef struct {
	uint32_t aid;
	uint8_t app;
	uint8_t key_id;
	uint8_t key_type;
	uint8_t key_num;
	uint8_t diversified;
}zkcfg_keyset_t;

typedef struct {
	zkcfg_key_data_t privacy;
	zkcfg_key_data_t credential;
}zkcfg_keys_t;

typedef struct {
	zkcfg_keyset_t privacy;
	zkcfg_keyset_t credential;
	uint8_t file_no;
	uint8_t offset;
	uint8_t length;
}zkcfg_cfg_t;


#pragma pack()

int zkcfg_read(uint32_t page, uint16_t offset, uint16_t length, void* data);

int zkcfg_write(uint32_t page, uint16_t offset, uint16_t length, const void* data);

int zkcfg_read_keys(zkcfg_keys_t* keys);

int zkcfg_write_keys(const zkcfg_keys_t* keys);

void zkcfg_get_default_keys(zkcfg_keys_t* keys);

void zkcfg_get_default_cfg(zkcfg_cfg_t * cfg);

void zkcfg_key_data_debug(const zkcfg_key_data_t* kdata, uint16_t count);

void zkcfg_keyset_debug(const zkcfg_keyset_t *keyset, uint16_t count);


#endif

